<template>
    <view class="createCustomer">
        <uni-nav-bar fixed left-icon="left" :title="title" @clickLeft="backHandle" class="unibarS">
            <block slot="right">
                <text class="sub-btn" @click="submit">保存</text>
            </block>
        </uni-nav-bar>
        <!-- 主要内容 -->
        <view class="customer-content">
            <u--form labelPosition="left" :model="params" :rules="rules" ref="uForm" labelWidth="70">
                <u-form-item class="testing-phone" borderBottom ref="item1">
                    <u--input v-model="phone" border="none" placeholder="请输入客户手机号"></u--input>
                    <view slot="right" class="slot-box" @click="customerIsExist()">
                        <u-icon name="search" size="22" color="#4DACB1"></u-icon>
                        <text class="testing-phone-text">查重</text>
                    </view>
                </u-form-item>
                <view class="item-title">基础信息</view>
                <u-form-item class="item-box" label="客户名称" borderBottom ref="item1">
                    <u--input v-model="params.customerName" border="none" placeholder="请填写"></u--input>
                </u-form-item>
                <u-form-item class="item-box" label="客户电话" borderBottom ref="item1">
                    <u--input v-model="params.phoneNumber" border="none" placeholder="请填写"></u--input>
                </u-form-item>
                <u-form-item class="item-box" label="客户类型" required prop="customerType"
                    @click="showSelect('customerType')" borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view :class="!params.customerType ? 'item-temp-text-empty' : ''">{{
                            bus_client_type[params.customerType] || '点击选择' }}</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
                <u-form-item class="item-box" label="客户状态" required prop="customerStatus" @click="showSelect('customerStatus')"
                    borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view :class="!params.customerStatus ? 'item-temp-text-empty' : ''">
                            {{ bus_customer_status[params.customerStatus] ||
                            '点击选择' }}</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
                <u-form-item class="item-box" label="客户星级" required prop="customerStarLevel" borderBottom ref="item1">
                    <view class="rate-box">
                        <u-rate v-model="params.customerStarLevel"></u-rate>
                    </view>
                </u-form-item>
                <u-form-item class="item-box" label="客户来源" required prop="opportunitySource" @click="showSelect('opportunitySource')"
                    borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view :class="!params.opportunitySource ? 'item-temp-text-empty' : ''">
                            {{ bus_source[params.opportunitySource]
                            || '点击选择' }}</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
                <u-form-item class="item-box" label="业务人员" required prop="businessManagerId" @click="selectHandle(1)"
                    borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view v-if="params.businessManagerId" class="avatar-box">
                            <u-avatar class="avatar" size="25"></u-avatar>
                            <text>{{ params.businessManagerName }}</text>
                        </view>
                        <view v-else class="item-temp-text-empty">点击选择</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
                <view class="item-title">更多信息</view>
                <u-form-item class="item-box" label="所在地区" @click="selectCityHandle()" borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view :class="!params.localProvince ? 'item-temp-text-empty' : ''">
                            {{ params.localProvinceName + params.localCityName + params.localCountyName ||
                            '点击选择' }}</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item>
                <!-- <u-form-item class="item-box" label="详情地址" @click="chooseAddressHandle()" borderBottom ref="item1">
                    <view class="item-temp-box">
                        <view :class="!params.detailedAddress ? 'item-temp-text-empty' : ''">{{ params.detailedAddress
                            || '点击选择' }}</view>
                    </view>
                    <u-icon slot="right" name="arrow-right"></u-icon>
                </u-form-item> -->
                <u-form-item class="item-box" label="详情地址" borderBottom ref="item1">
                    <u--input v-model="params.detailedAddress" border="none" placeholder="请填写详情地址"></u--input>
                </u-form-item>
                <u-form-item class="item-box" label="备注信息" labelPosition="top" borderBottom ref="item1">
                    <u--textarea v-model="params.remark" border="false" placeholder="请输入备注信息" count
                        style="margin-top: 20rpx; background: #CCCCCC19;"></u--textarea>
                </u-form-item>
                <u-form-item class="item-box" label="痛点需求" borderBottom ref="item1">
                    <u--input v-model="params.customerNeed" border="none" placeholder="请输入痛点需求"></u--input>
                </u-form-item>
                <u-form-item class="item-box" label="统一社会信用代码" required labelWidth="200" labelPosition="top" borderBottom ref="item1">
                    <u--textarea v-model="params.creditCode" border="false" placeholder="请填写统一社会信用代码" count
                        style="margin-top: 20rpx; background: #CCCCCC19;"></u--textarea>
                </u-form-item>
                <u-form-item class="item-box" label="门店图片" labelPosition="top" ref="item1">
                    <view class="img_list">
                        <view @click="showPhoto" class="upload_box">
                            <u-icon name="camera" color="#677585" size="26"></u-icon>
                            <view>上传图片</view>
                        </view>
                        <view class="img_box" v-for="(item, index) in params.storeImageUrl" :key="index">
                            <img @click="previewImg(index)" style="width: 164rpx; height: 164rpx;" :src="item" alt="">
                            <u-icon @click="delImg(index)" class="del_icon" name="close-circle" color="#677585" size="24"></u-icon>
                        </view>
                    </view>
                </u-form-item>
                <view class="item-title" style="display: flex; justify-content: space-between;">
                    <view>{{ params.customerType == '1003'? '作物结构' : '销售情况' }}</view>
                    <view @click="addSal()" style="color: #4dacb1;">新增</view>
                </view>
                <view v-if="params.cropStructuresList">
                    <template v-if="params.cropStructuresList.length > 0">
                        <view class="sal_box" v-for="(item, index) in params.cropStructuresList" :key="index" style="margin-bottom: 20rpx;">
                            <u-form-item class="item-box" label="年份" borderBottom ref="item1">
                                <u--input v-model="item.cropYear" type="number" border="none" placeholder="请输入年份"></u--input>
                            </u-form-item>
                            <template v-if="item.cropType == '2'">
                                <u-form-item class="item-box" label="主营产品" @click="selectProduct(index)" borderBottom ref="item1">
                                    <view class="item-temp-box">
                                        <view v-if="item.mainProducts" class="avatar-box">
                                            <text>{{ item.mainProductsName }}</text>
                                        </view>
                                        <view v-else class="item-temp-text-empty">选择主营产品</view>
                                    </view>
                                    <u-icon slot="right" name="arrow-right"></u-icon>
                                </u-form-item>
                                <u-form-item class="item-box" label="销售规模(万元)" labelWidth="200" ref="item1">
                                    <u--input v-model="item.salesVolume" type="number" border="none" placeholder="请输入年销售规模"></u--input>
                                </u-form-item>
                            </template>
                            <template v-else>
                                <u-form-item class="item-box" label="作物品种" @click="selectMain(index)" borderBottom ref="item1">
                                    <view class="item-temp-box">
                                        <view v-if="item.cropVariety" class="avatar-box">
                                            <text>{{ item.cropVarietyName }}</text>
                                        </view>
                                        <view v-else class="item-temp-text-empty">请选择作物品种</view>
                                    </view>
                                    <u-icon slot="right" name="arrow-right"></u-icon>
                                </u-form-item>
                                <u-form-item class="item-box" label="种植面积(亩)" labelWidth="200" borderBottom ref="item1">
                                    <u--input v-model="item.cropArea" type="number" border="none" placeholder="种植面积"></u--input>
                                </u-form-item>
                                <u-form-item class="item-box" label="农资年投入成本(元)" labelWidth="200" borderBottom ref="item1">
                                    <u--input v-model="item.cropCost" type="number" border="none" placeholder="农资年投入成本"></u--input>
                                </u-form-item>
                                <u-form-item class="item-box" label="种植月份" labelWidth="200" borderBottom ref="item1">
                                    <view class="item-temp-box">
                                    <picker mode="date" fields="month" :value="item.cropMonth" @change="bindDateChange($event, index)">
                                        <view style="display: flex; justify-content: flex-end;">
                                            <view :class="!item.cropMonth ? 'item-temp-text-empty' : ''">{{ item.cropMonth || '请选择' }}</view>
                                            <!-- <view :class="!item.cropMonth ? 'item-temp-text-empty' : ''">娃哈哈</view>
                                            <u-icon slot="right" name="arrow-right"></u-icon> -->
                                        </view>
                                    </picker>
                                </view>
                                </u-form-item>
                            </template>
               
                            <u-form-item class="item-box" label="" labelWidth="200" ref="item1">
                                <u-button @click="delSal(index)" type="error" :plain="true" text="删除"></u-button>
                            </u-form-item>
                        </view>
                    </template>
                    <template v-else>
                        <uni-load-more :status="status" />
                    </template>
                </view>
                <view class="item-title">跟进计划</view>
                <u-form-item class="item-box" label="创建下次跟进任务" labelWidth="140" borderBottom ref="item1">
                    <view class="item-switch">
                        <u-switch :disabled="editType" v-model="isFollow" @change="changeSwitch" size="20"></u-switch>
                    </view>
                </u-form-item>
                <template v-if="isFollow">
                    <u-form-item class="item-box" label="跟进时间" required prop="followupTime"
                        borderBottom ref="item1">
                        <!-- <u--input v-model="params.followupRecords.followupTime" disabled disabledColor="#ffffff"
                            placeholder="点击选择" border="none"></u--input> -->
                        <view class="item-temp-box">
                            <uni-datetime-picker v-model="params.followupRecords.followupTime">
                                <view :class="!params.followupRecords.followupTime ? 'item-temp-text-empty' : ''">{{ params.followupRecords.followupTime || '点击选择' }}</view>
                            </uni-datetime-picker>
                        </view>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
                    <u-form-item class="item-box" label="跟进内容" required prop="userInfo.followContent" borderBottom
                        ref="item1">
                        <u--input v-model="params.followupRecords.followupContent" border="none" placeholder="请填写"></u--input>
                    </u-form-item>
                    <u-form-item class="item-box" label="跟进人员" required prop="userInfo.staffId" @click="selectHandle(2)"
                        borderBottom ref="item1">
                        <view class="item-temp-box">
                            <view v-if="params.followupRecords.staffId" class="avatar-box">
                                <u-avatar class="avatar" size="25" :src="'/static/img/dd.png'"></u-avatar>
                                <text>{{ params.followupRecords.staffIdName }}</text>
                            </view>
                            <view v-else class="item-temp-text-empty">点击选择</view>
                        </view>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
                    <u-form-item class="item-box" label="任务提醒" prop="userInfo.remind" @click="showSelect('reminderType')"
                        borderBottom ref="item1">
                        <view class="item-temp-box">
                            <view :class="!params.followupRecords.reminderType ? 'item-temp-text-empty' : ''">{{
                                bus_followup_task[params.followupRecords.reminderType] || '点击选择' }}</view>
                        </view>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
                    <u-form-item class="item-box" label="提醒方式" prop="userInfo.remindType"
                        @click="showSelect('reminderMethod')" borderBottom ref="item1">
                        <view class="item-temp-box">
                            <view :class="!params.followupRecords.reminderMethod ? 'item-temp-text-empty' : ''">{{
                                bus_reminder_method[params.followupRecords.reminderMethod] || '点击选择' }}</view>
                        </view>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
                </template>

            </u--form>
        </view>
        <!-- 弹出选择菜单 -->
        <u-action-sheet :show="showActionSheet" :actions="actions" title="请选择" @close="showActionSheet = false"
            @select="selectSelect">
        </u-action-sheet>
        <!-- 选择跟进日期 -->
        <uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :date="info.date"
            :insert="info.insert" @confirm="confirmCalendar" @close="closeCalendar" />
            <!--  -->
        <u-picker :show="show" :columns="columns" keyName="cropName" @confirm="confirm" @cancel="show = false"></u-picker>
    </view>
</template>

<script>
import { convertToDict } from '@/common/utils'
import { upImage } from '@/common/utils'
import { del } from 'vue'
export default {
    data() {
        return {
            title: '创建客户',
            showActionSheet: false,
            // 选择地区
            showPicker: false,
            isFollow: false,
            phone: null,
            status: 'no-more',
            params: {
                phoneNumber: null,
                customerName: null,
                customerType: null,
                customerTypeName: null,
                customerStatus: null,
                customerStatusName: null,
                customerStarLevel: 0,

                opportunitySource: null, // 客户来源
				opportunityChannel:'1001',
                localProvince: null,
                localProvinceName: null,
                localCity: null,
                localCityName: null,
                localCounty: null,
                localCountyName: null,
                detailedAddress: '',
                businessManagerId: null, // 业务经理
                businessManagerName: null, // 业务经理
                remark: '',
                customerNeed: '',
                creditCode: '',
                storeImageUrl: [],
                cropStructuresList: [],
                followupRecords: {
                    followupTime: null,
                    followupContent: null,
                    staffId: null,
                    staffIdName: null,
                    reminderMethod: null,
                    reminderType: null,
                }
            },
            // 弹出底部弹出菜单，展示的集合
            actions: [],
            // 客户类型
            classTypeList: [],
            // 客户状态
            stateList: [],
            // 客户来源
            sourceList: [],
            // 任务提醒
            taskList: [],
            // 提醒方式
            remindList: [],
            rules: {
                'customerType': {
                    type: 'string',
                    required: true,
                    message: '请选择客户类型',
                    trigger: ['blur', 'change']
                },
                'customerStatus': {
                    type: 'string',
                    required: true,
                    message: '请选择客户状态',
                    trigger: ['blur', 'change']
                },
                'opportunitySource': {
                    type: 'string',
                    required: true,
                    message: '请选择客户来源',
                    trigger: ['blur', 'change']
                },
                'businessManagerId': {
                    type: 'string',
                    required: true,
                    message: '请选择业务员',
                    trigger: ['blur', 'change']
                },
            },
            radio: '',
            switchVal: false,
            count: 4,
            value: 2,
            // 存储属性，用于保存当前正在编辑的表单项
            tempPropName: null,
            showCalendar: false,
            info: {
                insert: false,
                selected: []
            },
            editID: null,
            editType: null,
            show: false,
            columns: [],
            cropIndex: null,
            listAll: []
        }
    },

    onLoad(options) {

        // 获取当前登录账号
		this.getUser()
        this.getCropVariety()
        this.getlistAll()

        // 提醒方式
        this.remindList = JSON.parse(uni.getStorageSync('bus_reminder_method'))
        this.bus_reminder_method = convertToDict(this.remindList)

        this.taskList = JSON.parse(uni.getStorageSync('bus_followup_task'))
        this.bus_followup_task = convertToDict(this.taskList)

        // 客户类型
        this.classTypeList = JSON.parse(uni.getStorageSync('bus_client_type'))
        this.bus_client_type = convertToDict(this.classTypeList)
        // 客户状态 
        this.stateList = JSON.parse(uni.getStorageSync('bus_customer_status'))
        this.bus_customer_status = convertToDict(this.stateList)

        this.sourceList = JSON.parse(uni.getStorageSync('bus_source'))
        this.bus_source = convertToDict(this.sourceList)

        if (options.id && options.type == 'edit') {
            this.editID = options.id
            this.editType = true
            this.title = '编辑客户'
            this.isFollow = false
            setTimeout(() => {
                this.getDetails()
            }, 500)
        }
    },

    methods: {
        getlistAll() {
            this.$http.get('/app/product/listAll', { pageNum: 1, pageSize: 500 }).then(res => {
				if (res.code == 200) {
					this.listAll = res.data
				} 
			})
        },
        getUser() {
            this.$http.get('/system/user/profile', {}).then(res => {
                if (res.code == 200) {
                    this.params.businessManagerId = res.data.userId
                    this.params.businessManagerName = res.data.createBy
                }
            })
        },
        getCropVariety() {
            this.$http.get('/app/crop_variety/list', {pageNum: 1, pageSize: 300}).then(res => {
                if (res.code == 200) {
                    console.log(res)
                    this.columns = [res.rows]
                }
            })
        },
        customerIsExist() {
            if (!this.phone) {
                uni.$u.toast('请输入手机号')
                return
            }
            this.$http.get('/app/customer/customerIsExist/' + this.phone, {}).then(res => {
                if (res.code == 200) {
                    uni.$u.toast('手机号不存在')
                } else {
                    uni.$u.toast(res.msg)
                }
            })
        },       
        // 去选择城市
		selectCityHandle() {
            let that = this
            uni.navigateTo({
                url: '/pages/other/selectCity',
                events: {
                    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                    someEvent: function (data) {
                        that.params.localProvince = data.data.localProvince.code
                        that.params.localProvinceName = data.data.localProvince.name
                        that.params.localCity = data.data.localCity.code
                        that.params.localCityName = data.data.localCity.name
                        that.params.localCounty = data.data.localCounty.code
                        that.params.localCountyName = data.data.localCounty.name

                    },
                },
                success: function (res) {
                    // console.log('success:' + JSON.stringify(res))
                    // let obj = { id: 5, name: "列表B2" }
                    // res.eventChannel.emit('emitDataHandle', { data: obj })
                }
            });
        },
        // 显示选择器
        showSelect(propName) {
            // 客户类型
            if (propName == 'customerType') {
                this.actions = this.classTypeList
            } else if (propName == 'customerStatus') {
                this.actions = this.stateList
            } else if (propName == 'opportunitySource') {
                this.actions = this.sourceList
            } else if (propName == 'reminderMethod') {
                this.actions = this.taskList
            } else if (propName == 'reminderType') {
                this.actions = this.remindList
            }
            this.tempPropName = propName
            this.showActionSheet = true
        },
        selectSelect(e) {
            // console.log(e)
            // this.params[this.tempPropName + 'Name'] = e.name
            this.params[this.tempPropName] = e.dictValue
            if(this.tempPropName == 'reminderMethod') {
                this.params.followupRecords.reminderMethod = e.dictValue
            }
            if(this.tempPropName == 'reminderType') {
                this.params.followupRecords.reminderType = e.dictValue
            }
            if(this.tempPropName == 'customerType') {
                this.params.cropStructuresList = []
            }
            // this.$refs.uForm.validateField('userInfo.' + this.tempPropName)
        },
        chooseAddressHandle() {
            let that = this
            uni.chooseLocation({
                success: function (res) {
                    that.params.detailedAddress = res.name + res.address
                }
            });
        },
        // 选择业务员
        selectHandle(type) {
            let that = this
            uni.navigateTo({
                url: '/pages/crm/customer/selectSalesman',
                events: {
                    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                    someEvent: function (data) {
						if(data.data.type == 1) {
							that.params.businessManagerId = data.data.userId
							that.params.businessManagerName = data.data.userName
						} else {
							that.params.followupRecords.staffId = data.data.userId
							that.params.followupRecords.staffIdName = data.data.userName
						}
                    },
                },
                success: function (res) {
					let obj = {}
					if(type == 1) {
						obj = {
							userId: that.params.businessManagerId, 
							userName: that.params.businessManagerName,
							avatar: that.params.avatar,
							type: type
						}
					} else {
						obj = {
							userId: that.params.followupRecords.staffId,
							userName: that.params.followupRecords.staffIdName,
							type: type
						}
					}
 
                    res.eventChannel.emit('emitDataHandle', { data: obj })
                }
            });
        },
        // 选择产品
        selectProduct(index) {
            let that = this
            uni.navigateTo({
                url: '/pages/other/selectProduct',
                events: {
                    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                    someEvent: function (data) {
                        that.$set(that.params.cropStructuresList[index], 'mainProducts', data.data.mainProducts)
                        that.$set(that.params.cropStructuresList[index], 'mainProductsName', data.data.mainProductsName)
                    },
                },
                success: function (res) {
                    let obj = { 
                        mainProducts: that.params.cropStructuresList[index].mainProducts,
                        mainProductsName: that.params.cropStructuresList[index].mainProductsName
                    }
                    res.eventChannel.emit('emitDataHandle', { data: obj })
                }
            });
        },
        // 主营产品
        selectMain(index) {
            this.cropIndex = index
            this.show = true
        },
        confirm(e) {
            console.log(e)
            this.$set(this.params.cropStructuresList[this.cropIndex], 'cropVariety', e.value[0].id)
            this.$set(this.params.cropStructuresList[this.cropIndex], 'cropVarietyName', e.value[0].cropName)
            this.show = false
        },
        changeSwitch() {
            console.log(this.isFollow)
        },
        // 打开日历
        openCalendar() {
            this.$refs.calendar.open()
        },
        // 确定日期
        confirmCalendar(e) {
            console.log(e)
            this.params.followupRecords.followupTime = e.fulldate
        },
        // 关闭日历
        closeCalendar() { },
        // confirm(e) {

        // },
        submit() {
            if(!this.params.customerType) return uni.$u.toast('请选择客户类型')
            if(!this.params.customerStatus) return uni.$u.toast('请选择客户状态')
            if(!this.params.customerStarLevel) return uni.$u.toast('请选择客户星级')
            if(!this.params.opportunitySource) return uni.$u.toast('请选择客户来源')
            if(!this.params.businessManagerId) return uni.$u.toast('请选择业务人员')
            if(this.isFollow) {
                if(!this.params.followupRecords.followupTime) return uni.$u.toast('请选择跟进时间')
                if(!this.params.followupRecords.followupContent) return uni.$u.toast('请选择跟进内容')
                if(!this.params.followupRecords.staffId) return uni.$u.toast('请选择跟进人员')
            }
            let obj = JSON.parse(JSON.stringify(this.params))
            if(!this.isFollow) {
                delete obj.followupRecords
            }
            obj.storeImageUrl = obj.storeImageUrl.join(',')
            if(this.editType) {
                this.$http.put('/app/customer', obj).then(res => {
                    let data = res.data
                    if (data.code == 200) {
                        uni.showToast({
                            title: '成功',
                            duration: 1000
                        });
                        setTimeout(() => {
                            uni.navigateBack()
                        }, 1000)
                    } 
                })
            } else {
                this.$http.post('/app/customer', obj).then(res => {
                    let data = res.data
                    if (data.code == 200) {
                        uni.showToast({
                            title: '成功',
                            duration: 1000
                        });
                        setTimeout(() => {
                            uni.navigateBack()
                        }, 1000)
                    } 
                })
            }

            // this.$refs.uForm.validate().then(res => {
            //     uni.$u.toast('校验通过')
            // }).catch(errors => {
            //     uni.$u.toast('校验失败')
            // })
        },
        // 获取客户详情
        getDetails() {
            this.$http.get('/app/customer/detailsInfo/' + this.editID, {}).then(res => {
                console.log(res)
				if (res.code == 200) {
                    // this.detailsData = res.data
                    this.params = res.data
                    console.log(this.params)
                    if(this.params.storeImageUrl) {
                        this.params.storeImageUrl = this.params.storeImageUrl? this.params.storeImageUrl.split(',') : []
                    }
                    console.log(this.params)
                    this.params.cropStructuresList.forEach(item => {
                        delete item.id
                        if(item.cropVariety) {
                            item['cropVarietyName'] = this.setcropVarietyName(item)
                        }
                        if(item.mainProducts) {
                            item['mainProductsName'] = this.setmainProductsName(item)
                        }
                    })
                    // this.params.localProvinceName = null
                    this.params.followupRecords = {
                        followupTime: null,
                        followupContent: null,
                        staffId: '3',
                        staffIdName: '用户1',
                        reminderMethod: null,
                        reminderType: null,
                    }
				} else {
					uni.$u.toast(res.msg)
				}
			}).catch(err => {
                console.log(err)
			})
        },
        setcropVarietyName(row) {
            let arr = this.columns[0]
            let index = arr.findIndex(item => item.id == row.cropVariety)
            return arr[index].cropName
        },
        setmainProductsName(row) {
            let index = this.listAll.findIndex(item => item.id == row.mainProducts)
            return this.listAll[index].productName
        },
        delSal(index) {
            this.params.cropStructuresList.splice(index, 1)
        },
        backHandle() {
            uni.navigateBack()
        },
        showPhoto() {
            let that = this
            uni.chooseImage({
                count: 9,
                sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album'], //从相册选择
                success: function (res) {
                    // console.log(res);
                    // console.log(res.tempFilePaths);
                    upImage(res.tempFilePaths).then(res => {
                        console.log(res)
                        that.params.storeImageUrl = [...that.params.storeImageUrl, ...res]
                    })
                }
            });
        },
        previewImg(index) {
            uni.previewImage({
                current: index,
                urls: this.params.storeImageUrl
            })
        },
        delImg(index) {
            this.params.storeImageUrl.splice(index, 1)
        },
        addSal() {
            if(!this.params.customerType) return uni.$u.toast('请选择客户类型')
            let obj = {
                cropType: this.params.customerType == '1003'? '1' : '2',
                cropYear: '',
                cropVariety: null,
                cropVarietyName: null,
                cropArea: '',
                cropCost: '',
                cropMonth: null,
                mainProducts: null,
                salesVolume: null
            }
            this.params.cropStructuresList.push(obj)
        },
        bindDateChange(e, index) {
            console.log(index)
            console.log(e.detail.value.split('-')[1])
            let cropMonth = e.detail.value.split('-')[1]
            this.$set(this.params.cropStructuresList[index], 'cropMonth', cropMonth)
        }
    }
}
</script>

<style lang="scss" scoped>
.unibarS {
    /deep/.uni-navbar__header {
        padding: 0 32rpx;
    }

    /deep/.uni-navbar__content {
        border-bottom: none !important;
        box-shadow: 0px 0px 4px rgba(136, 136, 136, 0.12);
    }

    .sub-btn {
        font-size: 32rpx;
        font-weight: 400;
        color: rgba(77, 172, 177, 1);
    }
}

.createCustomer {
    background: rgba(247, 248, 250, 1);
}

.customer-content {
    margin: 20rpx 0;
}

.testing-phone {
    border-radius: 16rpx;
    background: rgba(255, 255, 255, 1);
    padding: 0 32rpx;
    .slot-box {
        display: flex;
        align-items: center;
    }
    .testing-phone-text {
        font-size: 30rpx;
        font-weight: 400;
        color: rgba(77, 172, 177, 1);
    }
}

.item-box {
    border-radius: 16rpx;
    background: rgba(255, 255, 255, 1);
    padding: 0 32rpx;

    /deep/.u-input__content__field-wrapper__field {
        text-align: right !important;
    }

    .rate-box,
    .item-switch {
        width: 100%;
        display: flex;
        justify-content: flex-end;
    }
}

.item-title {
    padding: 48rpx 32rpx 20rpx 32rpx;
    font-size: 32rpx;
    font-weight: 500;
    color: rgba(12, 16, 25, 1);
}

.item-temp-box {
    flex: 1;
    text-align: right;
    width: 0;
    font-size: 30rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    >view {
        // 超出隐藏
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.item-temp-text-empty {
    font-size: 30rpx;
    font-weight: 400;
    color: rgba(100, 117, 136, 1);
}

.avatar-box {
    display: flex;
    justify-content: flex-end;
    align-items: center;

    .avatar {
        margin-right: 10rpx;
    }
}
.img_list {
	margin-top: 16rpx;
    display: flex;
    flex-wrap: wrap;
    .img_box {
        width: 164rpx;
        height: 164rpx;
        position: relative;
        .del_icon {
            position: absolute;
            top: 0;
            right: 0;
        }
    }
    > view {
        margin-right: 20rpx;
    }
}
.upload_box {
	width: 164rpx;
	height: 164rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	border-radius: 12rpx;
	background: #F7F8FA;
	> view {
		font-size: 24rpx;
		font-weight: 400;
		color: rgba(12, 16, 25, 1);
		margin-top: 8rpx;
	}
}
</style>